<template>
  <div class="app-container">
    <el-dialog title="APP推送" :visible.sync="open" width="50%" append-to-body :close-on-click-modal='false'>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="推送类型" porp="pushType">
          <el-radio-group v-model="form.pushType">
          <el-radio label="link">链接</el-radio>
          <el-radio label="topic">专题</el-radio>
          <el-radio label="activity">活动</el-radio>
          <el-radio label="goods">商品</el-radio>
        </el-radio-group>
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" maxlength="20"/>
        </el-form-item>
        <el-form-item label="推送标题" prop="pushTitle">
          <el-input v-model="form.pushTitle" maxlength="14"/>
        </el-form-item>
        <el-form-item label="推送内容" prop="content">
          <el-input type="textarea" v-model="form.content" :rows="2" maxlength="20"/>
          <span>APP推送标题不能超过14个字，内容不能超过20个字。</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCatUserLog, getCatUserLog, delCatUserLog, addCatUserLog, updateCatUserLog, exportCatUserLog } from "@/api/system/catUserLog";

export default {
  data() {
    return {
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        pushType: [
          { required: true, message: "请选择类型", trigger: "blur" }
        ],
        title: [
          { required: true, message: "请输入标题", trigger: "blur" }
        ],
        pushTitle: [
          { required: true, message: "请输入推送标题", trigger: "blur" }
        ],
        content: [
          { required: true, message: "请输入内容", trigger: "blur" }
        ],
      }
    };
  },
  created() {
  },
  methods: {
    init(accountId){
      this.open = true
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        type: undefined,
        title: undefined,
        pushTitle: undefined,
        content: undefined,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateCatUserLog(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
              }
            });
          } else {
            addCatUserLog(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
              }
            });
          }
        }
      });
    },
  }
};
</script>